const BASE_URL = 'https://restapi.amap.com/v3';
const WEB_KEY = '2416fc802319968a9ab2101af186db59';

function obj2parse(obj) {
    let parse = [];
    for (let k in obj) {
        if (obj.hasOwnProperty(k)) {
            parse.push(k + '=' + obj[k]);
        }
    }
    return parse.join('&');
}

export const searchPlaceAround = (data) => {
    data.key = WEB_KEY;
    let url = BASE_URL + '/place/around?' + obj2parse(data);
    return fetch(url).then((response) => response.json());
};

export const searchPlaceKeywords = (data) => {
    data.key = WEB_KEY;
    let url = BASE_URL + '/place/text?' + obj2parse(data);
    return fetch(url).then((response) => response.json());
};
